<?php
namespace app\common\wx;

use app\common\httpdown\HttpRequest;
use think\cache\driver\Redis;

class Token{        
    /**
    * 获取access_token
    */        
    public function getAccessToken($originalid) {
        /*$redis_prefix = config('prefix_config.redis_prefix');
        $wxconfig = config('wx_secret');
        $token_redis_key = $redis_prefix.'token_'.$wxconfig['originalid'];
        $redis = new Redis();
          
        $appid=$wxconfig['appid'];
        $appsecret=$wxconfig['appsecret'];        
        
        if ($redis->has($token_redis_key)) {
            return $redis->get($token_redis_key);            
        }

        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".trim($appid)."&secret=".trim($appsecret);
        $http = new HttpRequest();
        $result = $http->https_request($url);
        $jsoninfo = json_decode($result, true);
        $access_token = $jsoninfo["access_token"];
        $expires_time = $jsoninfo["expires_in"]-600;
        $redis->set($token_redis_key, $access_token, $expires_time);*/
        $redis = new Redis();
        $token_redis_key = "WX_CONFIG:OriginalId:".$originalid;
        $wx_config = $redis->get($token_redis_key);
        //$wx_config = json_decode($wx_config, true);
        return $wx_config['access_token'];
    }
}